package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Likeb;
import cn.wolfcode.trip.base.service.ILikebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/likeb")
public class LikebController {

    @Autowired
    private ILikebService likebService;
    //在登录状态下,根据用户id和文章id查询是否有当前点赞的信息
    /**
     * 获取当前点赞信息
     * 资源 /likeb
     * 动作 GET
     * 参数/{userId}/{strategyId}
     */
    @GetMapping("/{userId}/{strategyId}")
    public  Object getState(@PathVariable Long userId, @PathVariable Long strategyId ){

        Likeb likeb = likebService.selectLikebByUserId(userId, strategyId);

       /* if(likeb.isState()){
            //当前已经点赞
        }*/
        if (likeb == null) {
            //用户没有点过赞
            return false;
        }
        return true;
    }




    //在登录状态下,根据用户文章id查询当前点赞数
    /**
     * 获取当前点赞信息
     * 资源 /likeb
     * 动作 GET
     * 参数/{strategyId}
     */
    @GetMapping("/{strategyId}")
    public  Object getNumByLike(@PathVariable Long strategyId ){

        int num=likebService.getNumByLike( strategyId);

        return num;
    }


    /**保存和删除当前点赞信息
     * 资源 /likeb
     * 动作 POST
     * 参数/{userId}/{strategyId}
     *
     */
    @PostMapping("/{userId}/{strategyId}")
    public  void saveState(@PathVariable Long userId, @PathVariable Long strategyId ){

        //返回点赞数量
        likebService.save(userId,strategyId);
    }

}
